package com.letoken.platform.app.controller;

import com.letoken.platform.app.service.impl.RedEnvelopService;
import com.letoken.platform.pub.res.ApiResponse;
import com.letoken.platform.repo.app.req.user.RedEnvelopeGiveReq;
import com.letoken.platform.repo.app.req.user.RedEnvelopePageReq;
import com.letoken.platform.repo.app.req.user.RedEnvelopeReceiveReq;
import com.letoken.platform.repo.utlis.WebUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@RequestMapping("/red_envelope")
public class RedEnvelopeController {

    @Resource
    private RedEnvelopService redEnvelopService;

    @PostMapping("/give")
    public ApiResponse<?> give(@RequestBody RedEnvelopeGiveReq req) {
        return redEnvelopService.give(WebUtils.getUser(), req);
    }

    @PostMapping("/receive")
    public ApiResponse<?> receive(@RequestBody RedEnvelopeReceiveReq req) {
        return redEnvelopService.receive(WebUtils.getUser(), req.getId(), 1, Integer.MAX_VALUE);
    }

    @PostMapping("/details")
    public ApiResponse<?> details(@RequestBody RedEnvelopeReceiveReq req) {
        return redEnvelopService.details(WebUtils.getUserId(), req.getId(), 1, Integer.MAX_VALUE);
    }

    @PostMapping("/given/page")
    public ApiResponse<?> givenPage(@RequestBody RedEnvelopePageReq req) {
        return redEnvelopService.givenPage(WebUtils.getUserId(), req.getYear(), req.getPage(), req.getSize());
    }

    @PostMapping("/received/page")
    public ApiResponse<?> receivedPage(@RequestBody RedEnvelopePageReq req) {
        return redEnvelopService.receivedPage(WebUtils.getUserId(), req.getYear(), req.getPage(), req.getSize());
    }

    @PostMapping("/configs")
    public ApiResponse<?> configs() {
        if (null == WebUtils.getUser()) {
            throw new RuntimeException("not found user!!!!!!");
        }
        return redEnvelopService.configs();
    }

}
